package com.guaoran.interview.unit.test;

import org.junit.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author gucheng
 * @Description
 *  单元测试Demo
 * 2019-04-02 13:09
 */
public class UnitTestDemo {
    List<Integer> list = new ArrayList<>();
    Random random = new Random();
    @Before
    public void before(){
        System.out.println("before:"+list.size());
        for (int i = 0; i < 1000; i++) {
            list.add(i);
        }
    }
    @Before
    public void before2(){
        if(list.size()==0){
            list.add(1);
        }
    }
    @After
    public void after(){
        list.clear();
        System.out.println("after:"+list.size());
    }

    // 超时
    @Test(timeout = 1,expected=InterruptedException.class)
    public void test(){
        try {
            int s = random.nextInt(10);
            System.out.println(s);
            Thread.sleep(s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("test:"+list.size());
        Assert.assertEquals(list.size(),1001);
    }

    /**
     * 忽略 testIgnore test 方法
     */
    @Test
    @Ignore
    public void testIgnore(){
        System.out.println("testIgnore:"+list.size());
        Assert.assertNotNull(list.size());
    }

}
